String.prototype.replaceAll = function(s1,s2) { 
    		return this.replace(new RegExp(s1,"gm"),s2); 
		}
		
		$(document).ready(function(){
			var current = location.pathname.split("/")[1];
			if(current == null || current == "index.php" || current=="") current = "index";
			$("#navigater").find("li[index=\""+current+"\"]").addClass("active");		
			var leftHeight = $("#demo_menu").height();
			$.scrollUp({
		        scrollName: 'scrollUp', // Element ID
		        scrollDistance: 300, // Distance from top/bottom before showing element (px)
		        scrollFrom: 'top', // 'top' or 'bottom'
		        scrollSpeed: 100, // Speed back to top (ms)
		        easingType: 'linear', // Scroll to top easing (see http://easings.net/)
		        animation: 'fade', // Fade, slide, none
		        animationInSpeed: 200, // Animation in speed (ms)
		        animationOutSpeed: 200, // Animation out speed (ms)
		        scrollTitle: false, // Set a custom <a> title if required. Defaults to scrollText
		        scrollImg: true, // Set true to use image
		        activeOverlay: false, // Set CSS color to display scrollUp active point, e.g '#00FFFF'
		        zIndex: 2147483647 // Z-Index for the overlay
			});
						
			$("#demo_menu li.cur").removeClass("cur");
			$("#demo_menu li[id='10']").addClass("cur");
			
			$("button.btn").click(function(){
					var theme = $(this).attr("theme");
					var id = $(this).attr("id");
				
					if(theme != null) {
						window.location.href="index.php?p=10&theme="+theme;
					}
					else if(id != null) {
						if(id=="code") {
							
							$.get("./js/line-basic.js",function(result){
									$("#show_code").show();
									result = result.replaceAll("<","&lt;").replaceAll(">","&gt;");
									$(".code_space").html(result);
									$(".hi").show();
									setTimeout(autoSize,10);
							});
						}
						else if(id == "theme_code"){
							$.get("js/themes/default.js",function(result){
									$("#show_code").show();
									result = result.replaceAll("<","&lt;").replaceAll(">","&gt;");
									$(".code_space").html(result);
									$(".hi").show();
									setTimeout(autoSize,10);
							});
						}
						else if(id == "edit") {
							window.open("/test/index.php?from=demo&p=10");
						}
					}
			});
			$("#demo_url").find("input").bind("click",function(){
					$(this).select();
			});
			
			function autoSize() {
				var contentHeight = $("#demo_content").outerHeight();
				var menuHeight = $("#demo_menu").outerHeight();
				if(menuHeight < contentHeight) {
					$("#demo_menu").height(contentHeight);
				} else {
					if(contentHeight < leftHeight)
						contentHeight = leftHeight;
					$("#demo_menu").height(contentHeight);
				}
			}
		});